<template>
  <div class="app-container">
    <!-- 添加或修改订单管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="50%" >
      <el-form ref="form" :model="form" :rules="rules" label-width="100px" :disabled="true">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="订单编号" prop="num">
              <el-input v-model="form.num" placeholder="请选择服务" :readonly="true" >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="订单分类" prop="categoryName">
              <el-input v-model="form.categoryName" placeholder="请选择服务" :readonly="true" >
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="订单信息" prop="attribute">
              <el-input  v-model="form.attribute" placeholder="请输入订单信息" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
             <el-form-item label="规格属性" prop="tags">
              <el-input v-model="form.tags" placeholder="规格属性" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="预约时间" prop="orderTime">
              <el-date-picker clearable size="small"
                v-model="form.orderTime"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="选择预约时间">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="服务地址" prop="address">
              <el-input v-model="form.address" placeholder="请选择地址" :readonly="true"  >
                <el-button slot="append" icon="el-icon-search"></el-button>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="图片" prop="descImgUrl">
              <el-image v-if="form.descImgUrl"
                style="width: 80px; height: auto"
                :src="form.descImgUrl" z-index="9999"
                :preview-src-list="[form.descImgUrl]">
              </el-image>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- <el-row :gutter="20">
          <el-col :span="12">
             <el-form-item label="联系人" prop="username">
              <el-input v-model="form.username" placeholder="请输入联系人姓名" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系电话" prop="telephone">
              <el-input v-model="form.telephone" placeholder="请输入联系人电话" />
            </el-form-item>
          </el-col>
        </el-row> -->

        <!-- <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="单价" prop="price">
                <el-input  v-model="form.price" placeholder="请输入价格" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
             <el-form-item label="数量" prop="number">
                <el-input type="number" v-model="form.number" placeholder="请输入数量" @input="handleNumberInput" />
              </el-form-item>
            </el-col>
          </el-row> -->
        <el-row :gutter="10">
          <el-col :span="12">
           <el-row :gutter="0">
              <el-col :span="12">
                <el-form-item label="订单单价" prop="price">
                  <el-input v-model="form.price" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="订单数量" prop="number">
                  <el-input v-model="form.number"  />
                </el-form-item>
              </el-col>
            </el-row>
          </el-col>
          <el-col :span="12">
            <el-row :gutter="0">
              <el-col :span="12">
                <el-form-item label="应付金额" prop="payable">
                  <el-input v-model="form.payable" placeholder="请输入应付" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="实付金额" prop="pay">
                  <el-input v-model="form.pay" placeholder="请输入实付" />
                </el-form-item>
              </el-col>
            </el-row>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="备注" prop="detail">
              <el-input type="textarea" :rows="2" v-model="form.detail" placeholder="请输入备注" />
            </el-form-item>
          </el-col>
          <el-col :span="12">

          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="24">
                <el-tabs>
                  <el-tab-pane label="订单明细">
                    <el-table  :data="form.itemsList" max-height="200">
                      <el-table-column label="图片" align="center" prop="picUrl" >
                        <template slot-scope="scope">
                          <el-image
                            style="width: 30px; height: auto"
                            :src="scope.row.picUrl" z-index="9999"
                            :preview-src-list="[scope.row.picUrl]">
                          </el-image>
                        </template>
                      </el-table-column>
                      <el-table-column label="项目名称" align="center" prop="name" />
                      <el-table-column label="规格型号" align="center" prop="tags" />
                      <el-table-column label="指导价" align="center" prop="price" />
                      <el-table-column label="数量" align="center" prop="number" />
                      <el-table-column label="单位" align="center" prop="unit" />
                      <el-table-column label="成本价" align="center" prop="costPrice" />
                      <el-table-column label="普通接单价" align="center" prop="receivePrice" />
                      <el-table-column label="公司价" align="center" prop="receiveCompanyPrice" />
                      <el-table-column label="金额" align="center" prop="amount" />
                    </el-table>
                  </el-tab-pane>
                  <el-tab-pane label="接单信息">
                    <el-row :gutter="20">
                      <el-col :span="12">
                        <el-row :gutter="0">
                          <el-col :span="12">
                            <el-form-item label="接单人" prop="receiveName">
                              <el-input v-model="form.receiveName" placeholder="请选择接单人" :readonly="true"  >
                              </el-input>
                            </el-form-item>
                          </el-col>
                          <el-col :span="12">
                            <el-form-item label="接单电话" prop="receivePhone">
                              <el-input v-model="form.receivePhone" placeholder="请输入接单人电话" :readonly="true" />
                            </el-form-item>
                          </el-col>
                        </el-row>
                      </el-col>
                      <el-col :span="12">
                        <el-form-item label="接单价" prop="receivePhone">
                          <el-input v-if="form.companyId" v-model="form.receiveCompanyPrice"  :readonly="true" />
                          <el-input v-else v-model="form.receivePrice"  :readonly="true" />
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row :gutter="20">
                      <el-col :span="12">
                        <el-form-item label="所属公司" prop="company">
                          <el-input v-model="form.company" placeholder="请输入接单人所属公司" />
                        </el-form-item>
                      </el-col>
                      <el-col :span="12">
                        <el-form-item label="所属代理" prop="proxy">
                          <el-input v-model="form.proxy" placeholder="请输入接单人所属代理" />
                        </el-form-item>
                      </el-col>
                    </el-row>
                  </el-tab-pane>
                  <el-tab-pane label="支付记录">
                    <el-table  :data="form.paymentList">
                      <el-table-column label="支付金额" align="center" prop="amount" />
                      <el-table-column label="支付方式" align="center" prop="payWay" />
                      <el-table-column label="交易流水号" align="center" prop="transNo" />
                      <el-table-column label="类型" align="center" prop="payType" :formatter="formatPaytype" />
                      <el-table-column label="主题" align="center" prop="subject" />
                      <el-table-column label="内容" align="center" prop="body" />
                      <el-table-column label="支付状态" align="center" prop="status" >
                        <template slot-scope="scope">
                          <el-tag v-if="scope.row.status == 1" type="success" size="mini">已支付</el-tag>
                          <el-tag v-else type="danger" size="mini">未支付</el-tag>
                        </template>
                      </el-table-column>
                      <el-table-column label="支付时间" align="center" prop="successTime" width="180">
                        <template slot-scope="scope">
                          <span>{{ parseTime(scope.row.successTime) }}</span>
                        </template>
                      </el-table-column>

                    </el-table>
                  </el-tab-pane>
                  <el-tab-pane label="抢单记录">
                    <el-table  :data="form.receiveList" >
                      <el-table-column label="抢单人" align="center" prop="userName" />
                      <el-table-column label="联系电话" align="center" prop="userTelephone" />
                      <el-table-column label="抢单时间" align="center" prop="createTime" width="180">
                        <template slot-scope="scope">
                          <span>{{ parseTime(scope.row.createTime) }}</span>
                        </template>
                      </el-table-column>
                      <el-table-column label="备注" align="center" prop="remark" />
                      <el-table-column label="状态" align="center" prop="status" >
                        <template slot-scope="scope">
                          <el-tag v-if="scope.row.status == 1" type="success" size="mini">已确认</el-tag>
                          <el-tag v-else type="danger" size="mini">未确认</el-tag>
                        </template>
                      </el-table-column>
                    </el-table>
                  </el-tab-pane>
<!--                  <el-tab-pane label="检查记录">
                    <el-table :data="form.checkList" >
                      <el-table-column label="地址" align="center" prop="address" />
                      <el-table-column label="图片" align="center" prop="imgUrl" >
                        <template slot-scope="scope">
                          <el-image v-if="scope.row.imgUrl"
                            style="width: 100px; height: auto"
                            :src="scope.row.imgUrl"
                            :preview-src-list="[scope.row.imgUrl]">
                          </el-image>
                        </template>
                      </el-table-column>
                      <el-table-column label="结论" align="center" prop="result" :formatter="resultFomat" />
                    </el-table>
                  </el-tab-pane>-->
                  <el-tab-pane label="服务记录">
                    <el-table  :data="form.serviceList" >
                      <el-table-column label="服务人员" align="center" prop="receiveName" />
                      <el-table-column label="服务开始时间" align="center" prop="beginTime" width="180">
                        <template slot-scope="scope">
                          <span>{{ parseTime(scope.row.beginTime) }}</span>
                        </template>
                      </el-table-column>
                      <el-table-column label="服务结束时间" align="center" prop="endTime" width="180">
                        <template slot-scope="scope">
                          <span>{{ parseTime(scope.row.endTime) }}</span>
                        </template>
                      </el-table-column>
                      <el-table-column label="图片" align="center" prop="imgUrl" >
                        <template slot-scope="scope">
                          <el-image v-if="scope.row.imgUrl"
                            style="width: 100px; height: auto"
                            :src="scope.row.imgUrl"
                            :preview-src-list="[scope.row.imgUrl]">
                          </el-image>
                        </template>
                      </el-table-column>
                      <el-table-column label="备注" align="center" prop="remark" />
                    </el-table>
                  </el-tab-pane>
                  <el-tab-pane label="评价记录">
                    <el-table  :data="form.commentList" >
                      <el-table-column label="类型" align="center" prop="type" >
                        <template slot-scope="scope">
                          <div v-if="scope.row.type == 1">用户评价</div>
                          <div v-if="scope.row.type == 2">服务方评价</div>
                        </template>
                      </el-table-column>
                      <el-table-column label="评分" align="center" prop="score" >
                        <template slot-scope="scope">
                          {{scope.row.score}} 星
                        </template>
                      </el-table-column>
                      <el-table-column label="内容" align="center" prop="content" />
                      <el-table-column label="评论者" align="center" prop="createUserName" />
                      <!-- <el-table-column label="被评论者" align="center" prop="commentedUserName" /> -->
                      <el-table-column label="图片" align="center" prop="imgUrl" >
                        <template slot-scope="scope">
                          <el-image v-if="scope.row.imgUrl"
                            style="width: 100px; height: auto"
                            :src="scope.row.imgUrl" z-index="9999"
                            :preview-src-list="[scope.row.imgUrl]">
                          </el-image>
                        </template>
                      </el-table-column>
                    </el-table>
                  </el-tab-pane>
                  <el-tab-pane label="操作日志">
                    <el-table  :data="form.orderLogList"  max-height="200">
                      <el-table-column label="标题" align="center" prop="title" />
                      <el-table-column label="类别" align="center" prop="operatorType" :formatter="operatorTypeFormat" />
                      <el-table-column label="内容" align="left" prop="content" width="300" show-overflow-tooltip/>
                      <el-table-column label="操作人" align="left" prop="operName" />
                      <el-table-column label="当前状态" align="center" prop="status" :formatter="statusFormat" />
                      <el-table-column label="操作时间" align="center" prop="operTime" width="180">
                        <template slot-scope="scope">
                          <span>{{ parseTime(scope.row.operTime) }}</span>
                        </template>
                      </el-table-column>
                    </el-table>
                  </el-tab-pane>
                </el-tabs>

          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align:center;">
        <el-button @click="cancel">返 回</el-button>
      </div>

    </el-dialog>

  </div>
</template>

<script>
import { listOrder, getOrder, delOrder, addOrder, updateOrder, exportOrder } from "@/api/business/order";


export default {
  name: "Order",
  components: {

  },
  data() {

    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,

      // 状态数据字典
      statusOptions: [],
      payTypeOptions: [],
      resultOptions: [],
      operatorTypeOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        num: null,
        detail: null,
        orderTime: null,
        userId: null,
        username: null,
        telephone: null,
        receiveId: null,
        receiveName: null,
        receivePhone: null,
        receiveLimit: null,
        group: null,
        attribute: null,
        status: null,
        createName: null,
        createId: null,
        createTime: null,
        payable: null,
        pay: null,
        payMethod: null
      },
      // 表单参数
      form: {},

    };
  },
  created() {
    this.getDicts("tb_payment_type").then(response => {
      this.payTypeOptions = response.data;
    });
    this.getDicts("tb_check_reason").then(response => {
      this.resultOptions = response.data;
    });
    this.getDicts("tb_order_log_op_type").then(response => {
      this.operatorTypeOptions = response.data;
    });
    this.getDicts("tb_order_status").then(response => {
      this.statusOptions = response.data;
    });
  },
  methods: {
    init(data){
      this.open = false;
      getOrder(data.id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "订单详情";
        if (response.data.orderAddress) {
          this.form.address = response.data.orderAddress.detail;
        }
      });
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        num: null,
        detail: null,
        orderTime: null,
        userId: null,
        username: null,
        telephone: null,
        receiveId: null,
        receiveName: null,
        receivePhone: null,
        receiveLimit: null,
        group: null,
        attribute: null,
        status: 0,
        remark: null,
        createName: null,
        createId: null,
        createTime: null,
        payable: null,
        pay: null,
        payMethod: null,
        address: null,
        addressId: null,
        orderAddress: {
          address: null
        }
      };
      this.resetForm("form");
    },
    // 字典状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    // 操作类别字典翻译
    operatorTypeFormat(row, column) {
      return this.selectDictLabel(this.operatorTypeOptions, row.operatorType);
    },
    // 字典状态字典翻译
    resultFomat(row, column) {
      return this.selectDictLabel(this.resultOptions, row.result);
    },
       // 字典状态字典翻译
    formatPaytype(row, column) {
      return this.selectDictLabel(this.payTypeOptions, row.payType);
    },
  }
};
</script>
